﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace stuff
{
    public class AnimatedSprites
    {
        private Texture2D texture;
        private int rows;
        private int columns;
        private int current_frame;
        private int total_frames;

        public int Total_frames
        {
            get { return total_frames; }
            set { total_frames = value; }
        }

        public int Columns
        {
            get { return columns; }
            set { columns = value; }
        }
        public int Rows
        {
            get { return rows; }
            set { rows = value; }
        }
        public Texture2D Texture
        {
            get { return texture; }
            set { texture = value; }
        }
        public AnimatedSprites(Texture2D texture, int rows, int columns)
        {
            Texture = texture;
            Rows = rows;
            Columns = columns;
            Total_frames = Rows * Columns;
            current_frame = 0;
            
        }
        public AnimatedSprites(Texture2D texture, int rows, int columns ,int total)
        {
            Texture = texture;
            Rows = rows;
            Columns = columns;
            Total_frames = total;
            current_frame = 0;

        }
        public void Update()
        {
            current_frame++;
            if (current_frame == Total_frames)
                current_frame = 0;

        }
        public void Draw(SpriteBatch sprite, Vector2 position)
        {
            int width = Texture.Width / Columns;
            int height = Texture.Height / Rows;
            int row = (int)((float)current_frame / (float)Columns);
            int column = current_frame % Columns;

            Rectangle source = new Rectangle(width * column, height * row, width, height);
            Rectangle dest = new Rectangle((int)position.X, (int)position.Y, width, height);
            sprite.Begin();
            sprite.Draw(Texture, dest, source, Color.White);
            sprite.End();


        }
    }
}
